#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>

void intsig_handler(int signum, siginfo_t *siginfo, void *context) {
    printf("Received SIGINT (PID=%d)\n", getpid());
}

int main() {
    struct sigaction act;
    act.sa_sigaction = intsig_handler;
    act.sa_flags = SA_SIGINFO;
    sigemptyset(&act.sa_mask);  // 确保不阻塞任何信号

    if (sigaction(SIGINT, &act, NULL) < 0) {
        perror("sigaction failed");
        exit(1);
    }

    pid_t pid = fork();
    if (pid < 0) {
        perror("fork failed");
        exit(1);
    } else if (pid == 0) {  // 子进程
        printf("Child PID: %d\n", getpid());
        while(1) sleep(1);  // 子进程保持运行
    } else {  // 父进程
        printf("Parent PID: %d\n", getpid());
        while(1) sleep(1);
    }

    return 0;
}
